package Tudy

import "fmt"

var str string
var indexStr int
var stop =0

func T3main() {
	fmt.Println("LL(1）文法为：")
	fmt.Println("A->a(d|Ac)")
	fmt.Println("A->bBc")
	fmt.Println("B->aA")
	mByteSelect:=make(map[string]map[byte]bool)
	mByteSelect["A->aA1"]=make(map[byte]bool)
	mByteSelect["A->bBc"]=make(map[byte]bool)
	mByteSelect["A1->d"]=make(map[byte]bool)
	mByteSelect["A1->Ac"]=make(map[byte]bool)
	mByteSelect["B->aA"]=make(map[byte]bool)
	mByteSelect["B->bB"]=make(map[byte]bool)

	mByteSelect["A->aA1"]['a']=true
	mByteSelect["A->bBc"]['b']=true
	mByteSelect["A1->d"]['d']=true
	mByteSelect["A1->Ac"]['a']=true
	mByteSelect["A1->Ac"]['b']=true
	mByteSelect["B->aA"]['a']=true
	mByteSelect["B->bB"]['b']=true

	fmt.Scan(&str)
	A()
	if str[indexStr]=='#'{
		fmt.Println("main正确匹配")
	}else{
		fmt.Println("main错误")
	}
}
func Match(c byte){
	if str[indexStr]!=c{
		stop=1
		fmt.Println("错误")
	}else{
		indexStr++
	}
}
func A(){
	if str[indexStr]=='a'{
		fmt.Println("A->aA1")
		Match('a')
		A1()
	}else if str[indexStr]=='b'{
		fmt.Println("A->bBc")
		Match('b')
		B()
		Match('c')
	}else{
		fmt.Println("错误")
	}
}
func B()  {
	if str[indexStr]=='a'{
		fmt.Println("B->aA")
		Match('a')
		A()
	}else if str[indexStr]=='b'{
		fmt.Println("B->bB")
		Match('b')
		B()
	}

}
func A1()  {
	if str[indexStr]=='d'{
		fmt.Println("A1->d")
		Match('d')
	}else if str[indexStr]=='a'||str[indexStr]=='b'{
		fmt.Println("A1->Ac")
		A()
		Match('c')
	}else{
		fmt.Println("错误")
	}

}